﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using MODEL;

public partial class _Default : System.Web.UI.Page
{
    protected StringBuilder sbTableContent = new StringBuilder();
    protected int nextPage = 1;
    protected int prePage = 1;
    protected int nowPage = 1;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (new WebHelper().IsLogin())
        {
            //if (ViewState["nowPage"] != null)
            //{
            //    //记录当前页码(当前页码不一定为1，如果点击上一页或者下一页，页码也随之发生改变)
            //    ViewState["nowPage"] = 1;
            //}

            string isJump = Request.QueryString["jump"];
            if (!string.IsNullOrEmpty(isJump))
            {
                if (isJump.Equals("1"))
                {
                    nowPage = int.Parse(Request.QueryString["Page"]);
                    nowPage++;
                }
                if (isJump.Equals("0"))
                {
                    nowPage = int.Parse(Request.QueryString["Page"]);
                    nowPage--;
                }
                if (nowPage <= 0)
                {
                    nowPage = 1;
                }
            }

            LoadList(nowPage);
        }
        else
        {
            Response.Write("没登陆，滚粗重新登录");
        }
    }

    #region 加载学生列表
    /// <summary>
    /// 加载学生列表
    /// </summary>
    private void LoadList(int nPage)
    {
        StudentBLL bll = new StudentBLL();
        List<StudentModel> list = bll.QueryByPageIndex(nPage);
        if (list .Count!=0)
        {
            int index = 1 + ((nPage - 1) * 3);
            foreach (StudentModel model in list)
            {
                sbTableContent.Append("<tr><td>" + index.ToString() + "</td>");
                sbTableContent.Append("<td>" + model.SClass.CName + "</td>");
                sbTableContent.Append("<td>" + model.SLoginName + "</td>");
                sbTableContent.Append("<td>" + model.SCnName + "</td>");
                sbTableContent.Append("<td>" + (model.SGender ? "男" : "女") + "</td>");
                sbTableContent.Append("<td>" + model.STel + "</td>");
                sbTableContent.Append("<td>" + model.SAddtime.ToShortDateString() + "</td>");
                sbTableContent.Append("<td><a href='Modify.aspx?id=" + model.SID + "'>修改</a> <a href='javascript:AskDel(" + model.SID + ")'>删除</a>  <a href='ViewDetails.aspx?id=" + model.SID + "'>详细</a> </td></tr>");
                index++;
            }
        }
        else
        {
            nowPage--;
            LoadList(nowPage);
            
        }
    } 
    #endregion
}